﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;


public partial class DataBaseManage_DictionaryAdd : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            this.PopedomValidate(Layerid, QUERY);

            this.headers.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);//系统
            string url = "dictionary_add.aspx?upid=" + Request.Params["upid"] + "&layerid=" + Layerid;
            //this.headers.Text += "<img src='../images/subnav_dot.gif' width='9' height='9' />&nbsp;&nbsp;<a href='" + url + "'>字典详细信息</a>&nbsp;&nbsp";
            string upidstr = Request.Params["upid"];
            
            
            string pid = Request.Params["cid"];
            if (pid != null && pid != "")
            {
                DictionaryManageBLL dmb = new DictionaryManageBLL();
                DictionaryManageModel dmm = dmb.selectDictionary(int.Parse(pid));
                this.txtCnname.Text = dmm.Cnname;
                this.txtEnname.Text = dmm.Enname;
                this.txtRemark.Text = dmm.Remark;
                if (dmm.Availabilityflag == 0)
                {
                    this.chbAvailabilityflag.Checked = true;
                }
                else
                {
                    this.chbAvailabilityflag.Checked = false;
                }
                this.txtOrdernum.Text = dmm.Ordernum.ToString();
                this.txtStandby.Text = dmm.Standby1;
                this.txtStandby2.Text = dmm.Standby2;
                upidstr = dmm.Upid.ToString();
            }
            int upid = int.Parse(upidstr);
            string cheader = "";
            DictionaryManageBLL dmbll = new DictionaryManageBLL();
            while (upid > 0)
            {
                DictionaryManageModel dmm = dmbll.selectDictionary(upid);
                cheader = "&nbsp;&nbsp;<img src='../images/subnav_dot.gif' />&nbsp;&nbsp;<a href=\"dictionary_list.aspx?upid=" + upid + "&layerid=" + Layerid + "\">" + dmm.Cnname + "</a>" + cheader;
                upid = dmm.Upid;
            }
            headers.Text += cheader;
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string str = Request["upid"];
        Response.Redirect("dictionary_list.aspx?upid=" + str+"&layerid=" + Request.Params["layerid"]);
        return;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string str = Request["cid"];
        string upid = Request["upid"];
        if (str == null || str == "")
        {
            int ts;
            ts = insert();
            Response.Redirect("dictionary_list.aspx?upid=" + upid + "&layerid=" + Request.Params["layerid"]);
            return;
        }
        else
        {
            update();
            Response.Redirect("dictionary_list.aspx?upid=" + upid + "&layerid=" + Request.Params["layerid"]);
            return;
        }
    }
    private int insert()
    {
        int ts = 0;
        string str = Request["upid"];
        OgilvyOne.BLL.DictionaryManageBLL gtdictionary = new DictionaryManageBLL();
        OgilvyOne.Model.DictionaryManageModel gtdictionaryinfo = new DictionaryManageModel();
        gtdictionaryinfo.Upid = int.Parse(str);
        gtdictionaryinfo.Cnname = this.txtCnname.Text.ToString().Trim();
        gtdictionaryinfo.Enname = this.txtEnname.Text.ToString().Trim();
        gtdictionaryinfo.Remark = this.txtRemark.Text.ToString().Trim();
        if (chbAvailabilityflag.Checked == true)
        {
            gtdictionaryinfo.Availabilityflag = 0;
        }
        else
        {
            gtdictionaryinfo.Availabilityflag = 1;
        }
        if (this.txtOrdernum.Text.ToString().Trim() != "")
        { gtdictionaryinfo.Ordernum = int.Parse(this.txtOrdernum.Text.ToString().Trim()); }
        else { gtdictionaryinfo.Ordernum = 0; }
        gtdictionaryinfo.Standby1 = this.txtStandby.Text.ToString().Trim();
        gtdictionaryinfo.Standby2 = this.txtStandby2.Text.ToString().Trim();
        ts = gtdictionary.AddDictionary(gtdictionaryinfo);
        return ts;
    }

    private void update()
    {
        string str = Request["upid"];
        string strs = Request["cid"];
        OgilvyOne.BLL.DictionaryManageBLL gtdictionary = new DictionaryManageBLL();
        OgilvyOne.Model.DictionaryManageModel gtdictionaryinfo = new DictionaryManageModel();
        gtdictionaryinfo.Cid = int.Parse(strs);
        gtdictionaryinfo.Upid = int.Parse(str);
        gtdictionaryinfo.Cnname = this.txtCnname.Text.ToString().Trim();
        gtdictionaryinfo.Enname = this.txtEnname.Text.ToString().Trim();
        gtdictionaryinfo.Remark = this.txtRemark.Text.ToString().Trim();
        if (chbAvailabilityflag.Checked == true)
        {
            gtdictionaryinfo.Availabilityflag = 0;
        }
        else
        {
            gtdictionaryinfo.Availabilityflag = 1;
        }
        if (this.txtOrdernum.Text.ToString().Trim() != "")
        { gtdictionaryinfo.Ordernum = int.Parse(this.txtOrdernum.Text.ToString().Trim()); }
        else { gtdictionaryinfo.Ordernum = 0; }
        gtdictionaryinfo.Standby1 = this.txtStandby.Text.ToString().Trim();
        gtdictionaryinfo.Standby2 = this.txtStandby2.Text.ToString().Trim();

        int ts = gtdictionary.updateDictionary(gtdictionaryinfo);
    }
}
